{% extends "master.html" %}
{% block subtitle %} - 出入库管理 - 创建入库单{% endblock %}

{% block extCSS %}
<style type="text/css">
    .template,.atmtemplate{
        display : none;
    }
</style>
{% endblock %}


{% block extJS %}
<script src="{{url_for('static', filename='js/customize/ivtnt_add.js')}}" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
    var extPdts = [];

    function toSubmit(){
        var msg = [];
        clearMsg();
        $(".err").removeClass("err");
        
        var atleastone = false;
        var qtyinput = true;
        
        $("input[name^='qty_']").each(function(){
            var t = $(this);
            var max = parseInt(t.attr('maxqty'));
            
            if(!t.val()){
                qtyinput = false;
                t.addClass('err');
            }else if(!check_number(t.val())){
                msg.push('请正确填写数量,必须为数字！')   
            }
            
            atleastone = true;          
        })
        
        if(!atleastone){
            msg.push('请填写至少一个商品！')
        }


        if(!qtyinput){
            msg.push('请填写入库数量！');
        }

        if(msg.length > 0){
            alertError(msg);
            return false;
        }else{
            $("form").submit();  
        }
    }
    
    function toCancel(){
        redirect_alert("{{MSG_LEAVE_WITHOUT_SAVING}}","{{url_for('bpIvtnt.view')}}")
    }  

//]]>
</script>
{% endblock %}

{% block main %}
<div class="container">
    <div class="row">
        <ol class="breadcrumb">
          <li><a href="{{url_for('bpRoot.view')}}">主面板</a></li>
          <li><a href="{{url_for('bpIvtnt.view')}}">出入库管理</a></li>
          <li class="active">创建入库单</li>
        </ol>
    </div>
    <div class="row">
        <div class="btn-toolbar pull-right">
            <div class="btn-group"><button class="btn btn-primary" onclick="toSubmit()">{{BTN_SUBMIT}}</button></div>
            <div class="btn-group"><button class="btn btn-inverse" onclick="toCancel()">{{BTN_CANCEL}}</button></div>
        </div>
    </div>
    <div class="row">    
        <form class="" method='POST' action="{{url_for('.view',action='add')}}" enctype="multipart/form-data">
        <fieldset>
            <legend>入库单详情</legend>
            <div class="col-md-4">
                <input type="hidden" name="direction" id="direction" value="{{IVTNT_IN}}"/>
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="refer">入库于</label></label>
                    <div class="controls">
                        <select name="ivtID" id="ivtID">
                            {% for s in source %}
                                <option value="{{s.id}}">{{s.name|ss(c='IVTNAME')}}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="refer">涉及</label></label>
                    <div class="controls"><input type="text" name="refer" id="refer"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="remark">备注</label></label>
                    <div class="controls"><textarea name="remark" id="remark"></textarea></div>
                </div>
            </div>   
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="createTime">开单时间</label></label>
                    <div class="controls"><input type="text" name="createTime" id="createTime" class="datepicker" value="{{now()|fd}}"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="createTime">经办人</label></label>
                    <div class="controls"><input type="text" value="{{session['user_profile']['name']}}" readonly="true"/></div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="control-group controls-row">
                  <label class="control-label" for="attachment">附件</label>
                  <div class="controls">
                      <ul id="atmul" class="list-unstyled">
                          <li><input type="file" name="atm_10"/><a href="#" onclick="addAtm('atmtemplate','atmmk','#atmul')"><i class="glyphicon glyphicon-plus"></i></a></li>
                          <li class="atmtemplate"><input type="file" name="atm_x"/><a href="#" onclick="delAtm(this,'atmmk')"><i class="glyphicon glyphicon-minus"></i></a></li>
                      </ul>
                  </div>
                </div>
            </div>
                  
            <div class="col-md-12">
                <label>添加商品</label>
                <select id="field">
                    <option value="no">商品编号</option>
                    <option value="name">商品名称</option>
                </select>
                <input type="text" id="fieldValue" class="input-xxlarge" data-provide="typeahead" autocomplete="off" placeholder="请输入商品相关信息，回车添加商品并清空输入框信息"/>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <td class="col-md-1">&nbsp;</td>
                            <td class="col-md-3">商品编号</td>
                            <td class="col-md-2">商品名称</td>
                            <td>商品描述</td>
                            <td class="col-md-2">入库数量</td>
                            <td class="col-md-2">备注</td>                            
                        </tr>
                    </thead>
                    <tbody id="pdtlist">
                        
                    </tbody>                
                </table>
            </div>
        </fieldset>
        <fieldset>
            <legend>涉及的单个物品</legend>
            <textarea name="item" id="item"></textarea>
        </fieldset>
        </form>
    </div>
</div>


{% endblock %}